#ifndef __TwRaySceneQuery_H__
#define __TwRaySceneQuery_H__

#include "TwRay.h"
#include "TwGameObject.h"
#include <vector>

class TwSceneManager;

struct TwRaySceneQueryResultEntry
{
	// Distance along the ray
	float distance;
	// The movable, or NULL if this is not a movable result
	TwGameObject* movable;
	// Comparison operator for sorting
	bool operator < (const TwRaySceneQueryResultEntry& rhs) const
	{
		return this->distance < rhs.distance;
	}
};
typedef std::vector<TwRaySceneQueryResultEntry> TwRaySceneQueryResult;

class TwRaySceneQuery
{
public:
	TwRaySceneQuery(TwSceneManager* mgr);
	virtual ~TwRaySceneQuery();

	virtual void setRay(const TwRay& ray);
	virtual const TwRay& getRay() const;
	virtual void setSortByDistance(bool sort, unsigned short maxresults = 0);
	virtual bool getSortByDistance() const;
	virtual unsigned short getMaxResults() const;

	virtual TwRaySceneQueryResult& execute();
	virtual TwRaySceneQueryResult& getLastResults();
	virtual void clearResults();
	virtual bool queryResult(TwGameObject* obj, float distance);

protected:
	TwRay					mRay;
	bool					mSortByDistance;
	unsigned short			mMaxResults;
	TwSceneManager*			mParentSceneMgr;
	TwRaySceneQueryResult	mResult;
};

#endif //__TwRaySceneQuery_H__